1474A - Puzzle From the Future - CodeForces Solution


greedy *800

Please click on ads to support us..

Python Code:

for s in[*open(0)][2::2]:
 r='';p=0
 for x in map(int,s[:-1]):p=x+(x+1!=p);r+=str(p-x)
 print(r)

C++ Code:

#include<bits/stdc++.h>
#define ll long long
#define mint(a,b,c) min(a,min(b,c))
#define maxt(a,b,c) max(a,max(b,c))
#define FOR(n) for(int i=0;i<n;i++)
#define rFOR(n) for(int i=n;i>=0;i--)
#define F(n) for(int j=0;j<n;j++)
#define rF(a,n) for(int i=n;i>=a;i--)
#define all(a) a.begin(),a.end()
using namespace std;

void tc(){
    int n;cin>>n;
    string b;cin>>b;
    string a="1";
    int c;
    if(b[0]=='1')c=2;
    else c=1;
    for(int i=1 ; i<b.length() ; i++){
        if(b[i] == '0')
            if(c != 1){
                c=1;
                a+='1';
            }else{
                c = 0;
                a+='0';
            
        }else{
            if(c  != 2){
                c = 2;
                a+='1';
            }else{
                c = 1;
                a+='0';
            }
        }
    }
    cout<<a<<"\n";
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t;
    cin>>t;
    while(t--){
        tc();
    }
}


Comments

Submit
0 Comments
More Questions

263A - Beautiful Matrix
180C - Letter
151A - Soft Drinking
1352A - Sum of Round Numbers
281A - Word Capitalization
1646A - Square Counting
266A - Stones on the Table
61A - Ultra-Fast Mathematician
148A - Insomnia cure
1650A - Deletions of Two Adjacent Letters
1512A - Spy Detected
282A - Bit++
69A - Young Physicist
1651A - Playoff
734A - Anton and Danik
1300B - Assigning to Classes
1647A - Madoka and Math Dad
710A - King Moves
1131A - Sea Battle
118A - String Task
236A - Boy or Girl
271A - Beautiful Year
520B - Two Buttons
231A - Team
479C - Exams
1030A - In Search of an Easy Problem
158A - Next Round
71A - Way Too Long Words
160A - Twins
1A - Theatre Square